<?php
class IndexAction extends Action
{
    public function index()
    {
        redirect(U('Index/login'));
    }
    
    public function login()
    {
        $this->display();
    }
    
    public function doLogin()
    {
        if (md5($_POST['verify']) != $_SESSION['verify']) {
            $this->error('验证码错误');
        }
        
        $user = array(
            'id'       => '888',
            'name'     => 'admin',
            'email'    => 'admin@admin.com',
            'password' => md5('admin'),
        );
        if ($_POST['email'] !== $user['email'] || md5($_POST['password']) !== $user['password']) {
            $this->error('用户不存在或密码错误');
        }else {
            $_SESSION['admin_name'] = $user['name'];
            PassportService::loginAdmin($user['id']);
            redirect(U('System/index'));
        }
    }
    
    public function logout()
    {
        PassportService::logout();
        redirect(U('Index/login'));
    }
    
    public function verify()
    {
        import('ORG.Util.Image');
        Image::buildImageVerify();
    }
    
    public function demo()
    {
        $this->display('System:demo');
    }
}